package com.baizhi.controller;

import com.baizhi.common.PageDTO;
import com.baizhi.entity.Manager;
import com.baizhi.entity.Triage;
import com.baizhi.service.TriageService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("triage")
public class TriageController {
    private TriageService triageService;
    @Autowired
    public void setTriageService(TriageService triageService) {
        this.triageService = triageService;
    }
    @RequestMapping("addTriage")
    public String addTriage(Triage triage, HttpSession session){
        Manager m = (Manager) session.getAttribute("login");
        triage.setManager(m);//当前登陆医生  保存到分诊记录对象中的医生属性中
        triageService.insertTriage(triage);
        return "redirect:/patient/showPatient";//挂完号返回患者信息页面  跨包跳转要加"/"
    }
    @RequestMapping("showTriage")
    public String showTriage(PageDTO pageDTO, Map map){
        PageInfo<Triage> pageInfo = triageService.selectByDepartment(pageDTO.getDid(), pageDTO.getPageNum(), pageDTO.getPageSize());
        map.put("pageNum",pageDTO.getPageNum());
        map.put("totalPage",pageInfo.getPages());
        map.put("list",pageInfo.getList());
        map.put("dname",pageDTO.getDname());
        map.put("did",pageDTO.getDid());
        return "manager/triage/triageList";
    }
    @RequestMapping("updateTriage")
    public String updateTriage(Triage triage){
        System.out.println("更新分诊记录的收参："+triage);
        triageService.updateTriage(triage);
//        pageDTO.setDid(triage.getDepartment().getDid());
        return "redirect:showTriage";
    }
    @RequestMapping("getOne")
    public String getOneTriage(Integer tid,Map map){
        Triage triage = triageService.selectById(tid);
        map.put("triage",triage);
        return "manager/triage/updateTriage";
    }
/*    @RequestMapping("jiaoHao")
    public String hiaoHao(Integer tid){
        Triage triage = triageService.selectById(tid);
        triage.setStatus(1);
        triageService.updateTriage(triage);
        return "redirect:showTriage";
    }*/
}
